package redis

import "net"

type RedisConn struct {
	clientConn net.Conn
	dbIndex    int
}

func MakeRedisConn(conn net.Conn) *RedisConn {
	return &RedisConn{
		clientConn: conn,
		dbIndex:    0,
	}
}

func (this *RedisConn) SelectDBIdx(index int) {
	this.dbIndex = index
}

func (this *RedisConn) GetDBIdx() int {
	return this.dbIndex
}

// Write 回写数据给客户端
func (this *RedisConn) Write(bytes []byte) error {
	_, err := this.clientConn.Write(bytes)
	return err
}

// Close 关闭客户端连接
func (this *RedisConn) Close() error {
	err := this.clientConn.Close()
	return err
}

// GetRemoteAddr 获取客户端连接地址
func (this *RedisConn) GetRemoteAddr() net.Addr {
	return this.clientConn.RemoteAddr()
}
